﻿#include <QGridLayout>
//#include <QLabel>
#include "../include/plot.h"
#include "../src/utility/utility.h"
#include "../include/timebus.h"
#include "../include/plot.h"
#include "../include/infowidget.h"
#include "mainwindow.h"
#include "./gomessage.h"
#include "dataWidget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>

DataWidget::DataWidget(QWidget *parent) :QWidget(parent)
{
	setWindowFlags(Qt::Window | Qt::FramelessWindowHint
		| Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint
		| Qt::WindowMaximizeButtonHint);

     QString title[2] ={
         QString(QString::fromWCharArray(L"钢筋计")),
         QString(QString::fromWCharArray(L"应力计")),
     };
	 stationsNums = 0;
	 currentStation = 0;
	 gridLayout = new QGridLayout(this);
    for(int i = 0 ; i < N_WINDOWS; ++i) {
        dataWindow[i] = new Plot(this);
		if(i<=3){
			dataWindow[i]->setYLabel(title[0]+QString::number(i+1, 10));
			dataWindow[i]->setPenColor(1);
			dataWindow[i]->setYAxisScale(-5000,5000);
		}
		else if(i <=12)
		{
			dataWindow[i]->setYLabel(title[1]+QString::number(i-3, 10));
			dataWindow[i]->setPenColor(2);
			dataWindow[i]->setYAxisScale(-5000,5000);
		}else if(i == N_WINDOWS-2){
			dataWindow[N_WINDOWS-2]->setYLabel(QString::fromWCharArray(L"电压值"));
			dataWindow[i]->setPenColor(3);
			dataWindow[i]->setYAxisScale(0,50);
		}else if(i == N_WINDOWS-1){
			dataWindow[N_WINDOWS-1]->setYLabel(QString::fromWCharArray(L"G/Y趋势预测"));
			dataWindow[i]->setPenColor(3);
			dataWindow[i]->setYAxisScale(-5000,5000);
		}

    }
	for(int i = 0 ; i < 5; ++i){
		gridLayout->addWidget(dataWindow[i], 0, i);
		gridLayout->addWidget(dataWindow[5+i], 1, i);
		gridLayout->addWidget(dataWindow[10+i], 2, i);
	}
	gridLayout->setMargin(1);
	gridLayout->setSpacing(1);
	setMinimumSize(QSize(100,100));

    setLayout(gridLayout);
}

/*==================================================================    
 *    功能：   更新横坐标时间值，同时更新内部的数据
 *    输入参数：t为时间参数
 *    返回值： 
/*==================================================================*/
void DataWidget::updateDatawidgetUI(long t)
{
	//qDebug()<<QString::fromWCharArray(L"timeBus驱动UI检测")<<t<<endl;
    for(int i = 0; i < N_WINDOWS ; ++i)
        dataWindow[i]->setIndexByTime(t);
#if 0
        if(socketFlag == QAbstractSocket ::UnconnectedState) {
            QTimer::singleShot(0, this, SLOT(resetConnectServer()));
        }
#endif
}

DataWidget::~DataWidget()
{
    Utility::DESTORY_PTR(gridLayout);
    //
}
